//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.serve;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.chris.entity.loan;
import com.chris.entity.loanAll;
import com.chris.entity.register;
import com.chris.impl.loanImpl;
import com.chris.impl.registerImpl;
import com.chris.utils.DbConnection;
import com.chris.utils.JsonProcess;
import com.chris.utils.LogUtil;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/searchLoan"})
public class searchLoan extends HttpServlet {
    private final loanImpl dao = new loanImpl();
    private final registerImpl dao2 = new registerImpl();

    public searchLoan() {
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        PrintWriter writer = resp.getWriter();

        try {
            String account = req.getParameter("account");
            if (account != null) {
                List<loan> byAccount = this.dao.getByAccount(account);
                List<loanAll> ans = new ArrayList<>();
                for(var i :byAccount){
                    register byID = dao2.getByID(i.getJournal_id());
                    loanAll loanAll = new loanAll(byID.getJournal_title(),byID.getYear(),byID.getVolume(),byID.getIssue()
                    ,i.getBorrow_time(),i.getDue_time(),i.getReturned(),i.getReturn_time(),i.getJournal_id());
                    ans.add(loanAll);
                }
                writer.print(JSON.toJSONString(JsonProcess.respSuccess("成功", ans)));
            } else {
                writer.print(JsonProcess.respError("参数不能为空"));
            }
        } catch (Exception var6) {
            writer.print(JsonProcess.respError("参数错误"));
            LogUtil.log("参数错误",var6);
        }
        DbConnection.endServe();
    }
    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
    }
}

